home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / gemlib30.zoo / common.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-11  |  4.7 KB  |  183 lines

  1. /*
  2.  * Common part of gemlib bindings
  3.  *
  4.  *    ++jrb    bammi@cadence.com
  5.  *    modified: mj -- ntomczak@vm.ucs.ualberta.ca
  6.  */
  7. #define __IN_COMMON_C
  8. #include "common.h"
  9.  
  10. /* vdi binding arrays (extern everywhere else) */
  11. unsigned short    _contrl[CNTRLMAX];
  12. short        _intin[INTINMAX];
  13. short        _intout[INTOUTMAX];
  14. short        _ptsin[2 * PTSINMAX];    /* upto PTSINMAX vertices are allowed
  15.                        - currently 1024 */
  16. short        _ptsout[2 * PTSOUTMAX];    /* likewise */
  17.  
  18. /*
  19.  * aes binding arrays  - we need only global, other overlapped with
  20.  * arrays for vdi - see common.h
  21.  */
  22. unsigned short  _global[GLOBMAX];    /* this should be exact */
  23.  
  24. /* aes binding params */    
  25. void    *_aesparams[6] =       { (void *)&_control[0],
  26.                      (void *)&_global[0],
  27.                  (void *)&_int_in[0],
  28.                  (void *)&_int_out[0],
  29.                  (void *)&_addrin[0],
  30.                  (void *)&_addrout[0] };
  31. /* why did atari do this when apid is avail on appl_init ?? */
  32. int gl_apid;            /* initialized in appl_init */
  33. int gl_ap_version;        /* initialized in appl_init */
  34.  
  35. /* vdi binding params */
  36. void    *_vdiparams[5] =       { (void *)&_contrl[0],
  37.                  (void *)&_intin[0],
  38.                  (void *)&_ptsin[0],
  39.                  (void *)&_intout[0],
  40.                  (void *)&_ptsout[0] };
  41. /* 
  42.  * the common interface to aes 
  43.  *    int __aes__(coded control);
  44.  *    unsigned long coded control;
  45.  * coded control: (1 byte for each element of control in the long)
  46.  *    DD CC BB AA
  47.  * DD : aes opcode
  48.  * CC : sizeof _int_in
  49.  * BB : sizeof _int_out
  50.  * AA : sizeof _addrin
  51.  *
  52.  * Note: sizeof _addrout is needed only for rsrc_gaddr and is special
  53.  *     cased below.
  54.  *
  55.  * output: the value (int)_intout[0]
  56.  */
  57.  
  58. #ifdef __OLD__
  59. int __aes__(unsigned long coded_control)
  60. {
  61.     register unsigned char  *p = (unsigned char *)&coded_control;
  62.     register unsigned short *q = &_control[0];
  63.     
  64.     /* decode control */
  65.     do
  66.     {
  67.     *q++ = (unsigned short)(*p++);
  68.     } while(q < &_control[4]);
  69.     
  70.     /* only rsrc_gaddr() needs this */
  71.     *q = (_control[0] == 112) ? 1 : 0;
  72.     
  73.     /* call aes */
  74.     __asm__ volatile 
  75.     ("     movl    %0,    d1
  76.         movw    #0xc8, d0
  77.         trap    #2"
  78.      :                /* no outputs */
  79.      : "g"(&_aesparams[0])    /* inputs     */
  80.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  81.      );
  82.     return (int)_int_out[0];
  83. }
  84. #else
  85. /* 
  86.  * new more efficient coding thanks to Thomas Koenig (UI0T@DKAUNI2.BITNET)
  87.  * "I made use here of the movep instruction for the 680xx, which transfers
  88.  * data from a data register to alternate bytes of memory. The odd
  89.  * address makes sure that these bytes are transferred to the lower half
  90.  * of the words."
  91.  */
  92. int __aes__(unsigned long coded_control)
  93. {
  94. #ifdef __MBASE__
  95.   void *params=&_aesparams[0];
  96. #endif
  97.     /* call aes */
  98.     __asm__ volatile
  99.     ("  movel    %1,  d1
  100.     lea " RESOLVE_ADDRESS(__contrl)",a0 | arrays _contrl and _control overlap 
  101.     moveq    #0,  d0
  102.     movepl    d0,  a0@(0)    | clear high bytes of control array
  103.         movepl    d1,  a0@(1)
  104.         movl    %0,    d1
  105.         movw    #0xc8, d0    | note -- no movq here, it sign extends
  106.         trap    #2"
  107.      :                /* no outputs */
  108. #ifdef __MBASE__
  109.      : "g"(params), "g"(coded_control)    /* inputs     */
  110. #else
  111.      : "g"(&_aesparams[0]), "g"(coded_control)    /* inputs     */
  112. #endif
  113.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  114.      );
  115.     return (int)_int_out[0];
  116. }
  117. #endif
  118.  
  119. /* 
  120.  * the common interface to vdi
  121.  *    void __vdi__(coded contrl, handle);
  122.  *    unsigned long coded contrl;
  123.  *    int handle;
  124.  * coded contrl:
  125.  *    DD BB CC AA
  126.  * DD : subfunc         (_contrl[5])    5 bits
  127.  * BB : nvert. _ptsin    (_contrl[1])    11 (== # vertices, size = 2 * CC)
  128.  * CC : sizeof _intin     (_contrl[3])    8 bits
  129.  * AA : vdi opcode    (_contrl[0])    8
  130.  *
  131.  * output : void (because it is so inconsistent, individual binding funcs
  132.  *          will pull info out of the appro. binding arrays)
  133.  */
  134.  
  135. void __vdi__(unsigned long coded_contrl, int handle)
  136. {
  137. #ifdef __MBASE__
  138.   void *params=&_vdiparams[0];
  139. #endif
  140.  
  141.     /* decode contrl */
  142.     _contrl[0] = (unsigned short)(coded_contrl & 0xff);
  143.     _contrl[3] = (unsigned short)((coded_contrl >>= 8) & 0xff);
  144.     _contrl[1] = (unsigned short)((coded_contrl >>= 8) & 0x7ff);
  145.     _contrl[5] = (unsigned short)(coded_contrl >> 11);
  146.     
  147.     _contrl[6] = handle;
  148.     
  149.     /* call vdi */
  150.     __asm__ volatile
  151.     ("     movl    %0,    d1
  152.         movq    #0x73, d0
  153.         trap    #2"
  154.      :                /* no outputs */
  155. #ifdef __MBASE__
  156.      : "g"(params)    /* inputs     */
  157. #else
  158.      : "g"(&_vdiparams[0])    /* inputs     */
  159. #endif
  160.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  161.      );
  162. }
  163.  
  164. void vdi(void)
  165. {
  166. #ifdef __MBASE__
  167.   void *params=&_vdiparams[0];
  168. #endif
  169.     __asm__ volatile
  170.     ("     movl    %0,    d1
  171.         movq    #0x73, d0
  172.         trap    #2"
  173.      :                /* no outputs */
  174. #ifdef __MBASE__
  175.      : "g"(params)    /* inputs     */
  176. #else
  177.      : "g"(&_vdiparams[0])    /* inputs     */
  178. #endif
  179.      : "d0", "d1", "d2", "a0", "a1", "a2"    /* clobbered regs */
  180.      );
  181. }
  182. /* -eof- */
  183.